package com.sleep.psy.external_server.business.adjustment.controller;


import com.alibaba.fastjson.JSON;
import com.sleep.psy.external_server.business.adjustment.entity.AdjustmentPlanDetails;
import com.sleep.psy.external_server.business.adjustment.entity.vo.PlanSleepDetailsReq;
import com.sleep.psy.external_server.business.adjustment.service.AdjustmentPlanDetailsService;
import com.sleep.psy.external_server.result.ResultEnum;
import com.sleep.psy.external_server.result.ResultUtil;
import com.sleep.psy.external_server.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 调节方案详情 前端控制器
 * </p>
 *
 * @author wenliguo
 * @since 2025-08-12
 */
@Api(tags = "调节方案详情")
@RestController
@RequestMapping("/adjustmentPlanDetails")
public class AdjustmentPlanDetailsController {

    protected Logger logger = LoggerFactory.getLogger(AdjustmentPlanDetailsController.class);

    @Autowired
    private AdjustmentPlanDetailsService planDetailsService;

    /**
     * 获取每日的具体调节方案
     * @author wenliguo
     * @date 2025/8/17 14:38
     * @param req 请求参数
     * @return com.sleep.psy.main_server.result.Result<com.sleep.psy.main_server.business2.adjustment.entity.AdjustmentPlanDetails>
     */
    @PostMapping("/selectDetail")
    @ApiOperation(value = "获取每日的具体调节方案")
    public Result<AdjustmentPlanDetails> selectDetail(@Valid @RequestBody PlanSleepDetailsReq req) {

        logger.info("获取每日的具体调节方案参数:{}", JSON.toJSONString(req));
        try {
            return planDetailsService.selectDetail(req);
        } catch (Exception e) {
            logger.error("获取每日的具体调节方案出错", e);
            return ResultUtil.error(ResultEnum.SERVER_INTERNAL_ERROR);
        }
    }
}

